﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;


/// <summary>
/// 返回結果
/// </summary>
[DataContract]
class Car_Result {
    /// <summary>
    /// 公車ID
    /// </summary>
    [DataMember(Order = 0)]
    public int id { get; set; }
    /// <summary>
    /// 公車车牌
    /// </summary>
    [DataMember(Order = 1)]
    public string name { get; set; }
}
public partial class Service_CarList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["rtid"]) != null && !string.IsNullOrEmpty(Request.QueryString["city"]))
        {
            using (MyDb.Db db = new MyDb.Db())
            {
                IList<Car_Result> list = new List<Car_Result>();
                Car_Result item = null;
                using (DataTable dt2 = db.getDataTable(string.Format("select busid from busevent where Busstatus = '0' and routeid = '{0}' order by busid", Request.QueryString["rtid"]), "mess2"))
                {
                    foreach (DataRow rs2 in dt2.Rows)
                    {
                        item = new Car_Result();
                        item.name = rs2["busid"].ToString();
                        item.id = Convert.ToInt32(Request.QueryString["rtid"]);
                        list.Add(item);                       
                    }
                }
                Response.Write(string.Format("{{\"bus\":{0}}}", MyDb.JSON.stringify(list)));
                list.Clear();
                list = null;
            }
        }
        Response.End();
    }
}
